package org.bopis.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.bopis.services.db.DAOUsuario;
import org.bopis.utilidades.Utilidades;

/**
 * Bean que se encarga de gestionar el formulario de Login
 * @author i.fernandezmolina
 *
 */
public class LoginForm extends ActionForm {

	private static final long serialVersionUID = 1L;
	
	private String email = null;
	private String password = null;  	

  	public void setEmail(String email) 
  	{
	    this.email = email;
  	}
	
  	public String getEmail() 
  	{
	    return (this.email);
  	}
	
  	public String getPassword() 
  	{
	    return (this.password);
  	}
	
  	public void setPassword(String password) 
  	{
	    this.password = password;
  	}
	
  	/**
  	 * Validaciones del fomulario
  	 */
  	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) 
  	{
    	ActionErrors errors = new ActionErrors();
	
    	//los campos deben de ser obligatrorios
	    if (Utilidades.isVacia(email) || Utilidades.isVacia(password)) {
	    	reset(mapping, request);
	      	errors.add("email", new ActionMessage("login.password.and.email.required"));
    	}
	        	
    	return errors;
  	}
	
  	/**
   	 * Resetea todas las propiedades a sus valores por defecto.
   	 */
  	public void reset(ActionMapping mapping, HttpServletRequest request) 
  	{
    	this.password = null;
    	this.email = null;
  	}

}
